package com.wondersgroup.hs.mobile.report.designer;

import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.wondersgroup.hs.mobile.report.support.submitJob.NursingDocSubmitPane;
import com.wondersgroup.hs.mobile.report.support.submitJob.NursingDocSubmiter;
import javassist.*;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zarra on 2016/12/29.
 */
public class ModifyService {

    static boolean __modify__ = false;

    public static ClassPool defaultClassPool(){
        ClassPool cp =  ClassPool.getDefault();

        cp.appendSystemPath();

        try {
            Class<?> cls = Class.forName("com.fr.start.Designer");
            cp.appendClassPath(new ClassClassPath(cls));
            cp.appendClassPath(new ClassClassPath(ModifyService.class));
        }catch (Throwable e){
            e.printStackTrace();
        }
        return cp;
    }

    public static CtClass ctClass(ClassPool pool, String className) throws NotFoundException {
        return pool.get(className);
    }

    public static CtMethod ctMethod(CtClass ctClass, String methodName) throws NotFoundException {
        return ctClass.getDeclaredMethod(methodName);
    }



    public static void doModifyService() throws Exception{

        if (__modify__) return;

        ClassPool cp = defaultClassPool();

        cp.getAndRename("com.wondersgroup.hs.mobile.report.designer.SubmitVisitorListPane", "com.fr.design.write.submit.SubmitVisitorListPane").toClass();


//        CtClass ctSubmitVisitorListPane = ctClass(cp, "com.fr.design.write.submit.SubmitVisitorListPane");
//        if (ctSubmitVisitorListPane.isFrozen())
//        {
//            ctSubmitVisitorListPane.defrost();
//        }
//        CtMethod methodCreateNameableCreators= ctMethod(ctSubmitVisitorListPane, "createNameableCreators");
//        methodCreateNameableCreators.insertAfter("{ " +
//                "com.fr.design.gui.controlpane.NameableCreator[] o = $_;" +
//               // "com.wondersgroup.hs.mobile.report.designer.ModifyAction m = new com.wondersgroup.hs.mobile.report.designer.ModifyAction();" +
//               // "return m.addNameableCreator(o);" +
//                "return o;}");
//
//        //methodCreateNameableCreators.insertAfter("{ return  $_;}");
//        ctSubmitVisitorListPane.toClass();

        __modify__ = true;
    }
}
